public class Solution7 {
    /**
     * 整数反转
     */
    public int reverse(int x) {
        boolean flag = false;
        long longX = x;
        if (longX < 0) {
            longX = -longX;
            flag = true;
        }
        StringBuilder sb = new StringBuilder(String.valueOf(longX));
        sb.reverse();
        long y = Long.parseLong(sb.toString());
        if (flag) y = -y;
        if (y > Integer.MAX_VALUE || y < Integer.MIN_VALUE){
            return 0;
        } else {
            return (int) y;
        }
    }
}
